/*
 +-----------------------------------------------------------------------------------------------+
 | Project : UKAPI
 +-----------------------------------------------------------------------------------------------+
 | Project Description : Universal & Kernel API
 +-----------------------------------------------------------------------------------------------+
 | File Description :
 |   Graph
 |                                                 
 +-----------------------------------------------------------------------------------------------+
 | Licence : MIT Licence
 +-----------------------------------------------------------------------------------------------+
 | Copyright (c) 2006 Olivier Vanhoucke
 | 
 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 | and associated documentation files (the "Software"), to deal in the Software without 
 | restriction, including without limitation the rights to use, copy, modify, merge, publish, 
 | distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 
 | Software is furnished to do so, subject to the following conditions:
 | 
 | The above copyright notice and this permission notice shall be included in all copies or 
 | substantial portions of the Software.
 | 
 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 +-----------------------------------------------------------------------------------------------+
*/

#ifndef __UKAPI_UNI_GRAPH__
#define __UKAPI_UNI_GRAPH__

#include <set.h>

typedef struct 
{
	pointer_t	sommet; // rename peek ?
	set_t		adjacent;
} adjacent_list_t, * padjacent_list_t;

typedef struct 
{
	size_t	nb_s;
	size_t	nb_a;
	int32_t			(*corresp)( const pointer_t key1, const pointer_t key2 );
	void			(*destroy)( pointer_t data );
	list_t			adjacent_list;
} graph_t, * pgraph_t;

typedef enum 
{ 
	vertex_color_white_e, 
	vertex_color_grey_e, 
	vertex_color_black_e 
} vertex_color_t; // translate in english

#define graph_adjacent_lists( graph )	( (graph)->adjacent_list )
#define graph_vcount( graph )			( (graph)->nb_s )
#define graph_ecount( graph )			( (graph)->nb_a )

#ifdef __cplusplus
	extern "C" {
#endif /* __cplusplus */

int graph_create( pgraph_t graph, 
              int32_t (*corresp)( const pointer_t key1, const pointer_t key2 ),
			  void (*destroy)( pointer_t data ) );
int graph_destroy( pgraph_t graph );
int graph_insert_vertex( pgraph_t graph, const pointer_t data );
int graph_insert_edge( pgraph_t graph, const pointer_t data1, const pointer_t data2 );
int graph_remove_vertex( pgraph_t graph, ppointer_t data );
int graph_remove_edge( pgraph_t graph, pointer_t data1, ppointer_t data2 );
int graph_adjacent_list( const pgraph_t graph, const pointer_t data, padjacent_list_t * adjacent_list );
int graph_is_adjacent( const pgraph_t graph, const pointer_t data1, const pointer_t data2 );

#ifdef __cplusplus
	}
#endif /* __cplusplus */

#endif /* __UKAPI_UNI_GRAPH__ */
